package com.itheima.chapter08.set.map.hashmap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

//HashMap存储学生对象并遍历
public class Hashmapdemo1 {
    public static void main(String[] args) {
        HashMap<String,Student> hm=new HashMap<>();
        Student s1 =new Student("zhangsan",23);
        Student s2 =new Student("lisi",22);
        Student s3 =new Student("wangwu",13);
        Student s4 =new Student("sunliu",31);
        hm.put("heima001",s1);
        hm.put("heima002",s2);
        hm.put("heima003",s3);
        hm.put("heima004",s4);
        Set<String> keySet = hm.keySet();
        for (String key : keySet) {
            Student values = hm.get(key);
            System.out.println(key+" "+values);
        }
        System.out.println("================");
        Set<Map.Entry<String, Student>> entrySet = hm.entrySet();
        for (Map.Entry<String, Student> ss : entrySet) {
            String key = ss.getKey();
            Student value = ss.getValue();
            System.out.println(key+" "+value);
        }
    }
}
